// pages/orderEditAddress/orderEditAddress.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    addressList:[],   //查询的收货地址列表
    radio: '',      //进到页面的初始地址id
    orderid:''   //订单id
  },
  // 修改收货地址提交数据
  submit(){
    var that = this
    //点击获取addressid   地址id
    that.data.addressid = that.data.radio
    // console.log('that.data.addressid',that.data.addressid)
    //当前页面
    let pages = getCurrentPages();
    
    //上一页面
    let prevPage = pages[pages.length - 2];
    //将数值信息赋值给上一页面cityItem变量
    prevPage.setData({
      addressid: that.data.addressid
    });
    
    //关闭当前界面返回到上一页面
    wx.navigateBack({
      delta: 1
    })




   
  },
  // 修改选中的收货地址
  onChange(event) {
    console.log('event.detail',event.detail)
    this.setData({
      radio: event.detail,
    });

  },
  
  // 查询收货地址列表
  getaddressList(){
    var that = this
    wx.request({
      url: getApp().globalData.baseUrl + '/wago/address/select',
      data: {
        userid:getApp().globalData.openid,
        page:1,
        size:100
      },
      method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: function(res){
        // success
        console.log('res',res.data.data)
        if(res.data.flag){
          that.setData({
            addressList:res.data.data
          })
          var addlist = that.data.addressList
          for(var i = 0;i < addlist.length;i++){
            addlist[i].namefirst = addlist[i].name.slice(0,1)
          }
          that.setData({
            addressList:addlist
          })
        }
      },
      fail: function() {
        // fail
      },
      complete: function() {
        // complete
      }
    })
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('传递的数据',options.addressid)
    
    this.setData({
      orderid:options.orderid,
      radio:options.addressid
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getaddressList()
  },

})